{% extends "tcms_base.html" %}
{% load i18n %}
{% load static %}

{% block subtitle %}{{ test_run.summary }}{% endblock %}

{% block custom_javascript %}
<!-- temporary workaround so we can convert addRunTag/removeRuntag to JSON RPC -->
<!-- FA CSS needed for the delete tag icon -->
<link rel="stylesheet" href="{% static 'font-awesome/css/font-awesome.min.css' %}">
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'js/jsonrpc.js' %}"></script>
<script src="{% static 'js/bugs.js' %}"></script>

<script type="text/javascript" src="{% static 'js/testrun_actions.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testcase_actions.js' %}"></script>
<script type="text/javascript">
{#　Define the status array for all of case run status　#}
Nitrate.TestRuns.CaseRunStatus = new Array();
{% for crs in test_status %}
Nitrate.TestRuns.CaseRunStatus.push('{{ crs.name|lower }}');
{% endfor %}
Nitrate.Utils.after_page_load(Nitrate.TestRuns.Details.on_load);
</script>
<script type="text/javascript">
jQ(function() {
    initialize_addlink_dialog();
});
</script>
{% endblock %}

{% block content_type %}
	<input type="hidden" name="content_type" value="testruns.testrun" />
	<input type="hidden" name="object_pk" value="{{ test_run.pk }}" />
	<input type="hidden" name="name" value="{{ test_run.name }}" />
	<input type="hidden" name="description" value="{{ test_run.notes }}" />
{% endblock %}

{% block contents %}
<div id="content">
	<!-- Store some values for easier javascript acccess -->
	<div id="tcms_values" class="hidden">
		<input id="value_run_id" type="hidden" name="run_id" value="{{ test_run.run_id }}" />
		<input id="value_product_id" type="hidden" name="product_id" value="{{ test_run.plan.product_id }}" />
	</div>
	<div class="control">
		{% if perms.testruns.change_testexecution %}
                <a href="{% url 'testruns-edit' test_run.pk %}"><strong>EDIT</strong></a>
		{% endif %}
		{% if perms.testruns.add_testrun %}
		<input id="btn_clone" type="button" value="Clone" title="Clone test run to other test build" data-param="{% url 'testruns-clone' test_run.pk %}" />
		{% else %}
		<input type="button" value="Clone" disabled="true"/>
		{% endif %}
		{% if perms.testruns.delete_testrun %}
                <a href="{% url 'admin:testruns_testrun_delete' test_run.pk %}"><strong>DELETE</strong></a>
		{% endif %}
	</div>
	<h2 id="display_title">{{ test_run.summary }}</h2>
	<div>
	<div class="listinfo_content" style="float:left; width:auto; margin-bottom:0px;">
		<div ></div>
		<div class="leftlistinfo">
			<div class="listinfo">
                            <div class="title grey">{% trans "Test Plan" %}&nbsp;:</div>
				<div class="name">
					<a href="{% url 'test_plan_url_short' test_run.plan.pk %}">[{{ test_run.plan.pk }}] {{ test_run.plan.name }}</a>
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Product Version" %}&nbsp;:</div>
				<div class="name">
					<a href="{% url "testruns-search" %}?product={{ test_run.plan.product_id }}&product_version={{ test_run.plan.product_version_id }}" title="Search test runs of {{ test_run.plan.product_version.value }}">{{ test_run.plan.product_version.value }}</a>
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Manager" %}&nbsp;:</div>
				<div class="name">
					<a href="{% url "tcms-profile" test_run.manager.username %}">{{ test_run.manager.username }}</a>
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Started at" %}&nbsp;:</div>
				<div class="name">
				{{ test_run.start_date|date:"Y-m-d H:i:s" }}
				</div>
			</div>
			<div class="listinfo" >
                            <div class="title grey">{% trans "Tags" %}&nbsp;:</div>
				<div class="name linotype">
					<ul class="js-tag-ul">
						{% for tag in test_run.tag.all %}
						<li>
							{{ tag }}
						{% if perms.testruns.delete_testruntag %}
						<a href="#" class="js-remove-tag" data-params='["{{ test_run.run_id }}", "{{ tag }}"]'>
                                                    <i class="fa fa-trash-o"></i>
                                                </a>
						{% endif %}
						</li>
						{% endfor %}
					</ul>
					{% if perms.testruns.add_testruntag %}
					<div>
                                            <input id="id_tags" type="text">
                                            <a class="addlink js-add-tag" href="#" data-param="{{ test_run.run_id }}">Add Tag</a>
                                            <div id="id_tags_autocomplete"></div>
                                        </div>
					{% endif %}
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Note" %}&nbsp;:</div>
				<div class="name" style="max-width:500px;">{{ test_run.notes|urlize|linebreaksbr }}</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="rightlistinfo">
			<div class="listinfo">
                            <div class="title grey">{% trans "Product" %}&nbsp;:</div>
				<div class="name">
					<a href="{% url "testruns-search" %}?product={{ test_run.product_version.product_id }}" title="Search test runs of {{ test_run.product_version.product }}">{{ test_run.product_version.product }}</a>
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Build" %}&nbsp;:</div>
				<div class="name">
					<a href="{% url "testruns-search" %}?product={{ test_run.plan.product_id }}&product_version={{ test_run.plan.product_version_id }}&build={{ test_run.build_id }}" title="Search test runs of {{ test_run.build_id }}">{{ test_run.build }}</a>
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Default Tester" %}&nbsp;:</div>
				<div class="name">
					{% if test_run.default_tester %}
					<a href="{% url "tcms-profile" test_run.default_tester.username %}">{{ test_run.default_tester.username }}</a>
					{% else %}
					{{ test_run.default_tester }}
					{% endif %}
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Status" %}&nbsp;:</div>
				<div class="name">
					{% if test_run.stop_date %}
                                        <span class="pauselink"> {% trans "Finished" %} </span>
					{% if perms.testruns.change_testrun %}
					<input type="button"  class="spadelink js-set-running" value="Set to Running" data-param="{% url 'testruns-change_status' test_run.run_id %}">
					{% endif %}
					{% else %}
                                        <span class="runninglink">{% trans "Running" %}</span>
					{% if perms.testruns.change_testrun %}
					<input type="button"class="spadelink js-set-finished" value="Set to Finished" data-param="{% url 'testruns-change_status' test_run.run_id %}">
					{% endif %}
					{% endif %}
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "Finished at" %}&nbsp;:</div>
				<div class="name">
				{{ test_run.stop_date|date:"Y-m-d H:i:s" }}
				</div>
			</div>
			<div class="listinfo">
                            <div class="title grey">{% trans "CC" %}&nbsp;:</div>
				<div class="linotype name">
					{% include 'run/get_cc.html' %}
				</div>
			</div>
		<div class="clear"></div>
	</div>

	{% include 'run/status_statistics.html' %}

	<div class="clear"></div>
	</div>
	<div class="Detailform border-1">
		{% include 'run/get_case_runs.html' %}
	</div>
</div>
{% endblock %}
